<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:a4j="http://richfaces.org/a4j"
        >

<ui:component>


        <script type="text/javascript" language="JavaScript">
            var selectedTab = 'mailbox';
        </script>

        <rich:tabPanel id="massageTabs" switchType="client">
            <rich:tab id="mailbox" ajaxSingle="true" label="Mailbox" onlabelclick="selectedTab = 'mailbox';">

                <ui:include src="mailbox.xhtml">

                </ui:include>

            </rich:tab>

            <c:forEach items="#{mailSessionBean.openConversations}" var="conversation" varStatus="var">
                <rich:tab id="conversation_#{conversation.uniqueKey}" ajaxSingle="true"
                          onlabelclick="selectedTab = 'conversation_#{conversation.uniqueKey}';">
                    <f:facet name="label">
                        <h:panelGroup>

                            <h:outputText value="#{conversation.subject}" style="text-align:left"/>
                            <rich:spacer width="20" height="10" title="|"/>
                            <h:graphicImage value="./style/images/closeTab.png" style="cursor:pointer"
                                            styleClass="hidelink"
                                            onclick="deleteTab('#{conversation.uniqueKey}');Event.stop(event); selectedTab='mailbox';"/>

                        </h:panelGroup>
                    </f:facet>

                    <ui:include src="conversation.xhtml">
                        <ui:param name="conversation" value="#{conversation}"/>
                    </ui:include>

                </rich:tab>
            </c:forEach>

            <rich:tab id="compose" ajaxSingle="true" label="#{resources.mailboxComposeLabel}">
                <h:form>
                    <ui:include src="compose.xhtml">
                        <ui:param name="showTopic" value="true"/>
                        <ui:param name="showReceivers" value="true"/>
                    </ui:include>
                    <h:panelGroup layout="block" style="text-align:right">
                        <a4j:commandButton value="#{resources.composeSendButton}" reRender="massageTabs" action="#{createMessageBean.send}"
                                           oncomplete="RichFaces.switchTab('#{rich:clientId('massageTabs')}', selectedTab,'');"/>
                        <a4j:commandButton value="#{resources.composeDiscardButton}" type="reset"
                                           oncomplete="RichFaces.switchTab('#{rich:clientId('massageTabs')}', selectedTab,'');"/>
                    </h:panelGroup>
                </h:form>
            </rich:tab>
        </rich:tabPanel>
        <h:form>
            <a4j:jsFunction reRender="massageTabs" name="deleteTab"
                            action="#{controlConversationBean.closeConversation}"
                            oncomplete="RichFaces.switchTab('#{rich:clientId('massageTabs')}', selectedTab,'');">
                <f:param name="conversationKey"/>
            </a4j:jsFunction>
        </h:form>
</ui:component>


</html>
